home *** CD-ROM | disk | FTP | other *** search
- #include "Class_ProgressWindow.h"
- #include "QDUtils.h"
-
- enum {
- kDefaultReadDelay = 1, // 5 ticks
-
- kProgressWindowWidth = 260,
- kProgressWindowHeight = 70,
-
- kProgressBarTop = kProgressWindowHeight - 20,
- kProgressBarHeight = 13,
-
- kPrimaryStrLeftPos = 20,
- kPrimaryStrBotPos = 18,
- kSecondaryStrLeftPos = kPrimaryStrLeftPos,
- kSecondaryStrBotPos = kPrimaryStrBotPos + 16,
-
- kProgressWindowBackColor = 56797
- };
-
- // ---------------------------------------------------------------------------
-
- ProgressWindow::ProgressWindow(GDHandle targetMonitor, short maxValue) {
- Rect windowBounds;
-
- this->primaryStr[0] = 0;
- this->secondaryStr[0] = 0;
- this->readDelay = kDefaultReadDelay;
-
- SetRect(&windowBounds, 0, 0, kProgressWindowWidth, kProgressWindowHeight);
- CenterRect(&windowBounds, &(**targetMonitor).gdRect);
- MoveRectTo(&windowBounds, windowBounds.left, 100);
-
- this->progressWindow = NewCWindow(NULL,
- &windowBounds,
- "\p ",
- false,
- altDBoxProc,
- (WindowPtr)-1,
- false,
- 0);
- SetPort(this->progressWindow);
-
- FlushRectTopLeft(&windowBounds);
-
- RGBColor backColor;
- // Light gray
- backColor.red = backColor.green = backColor.blue = kProgressWindowBackColor;
- RGBBackColor(&backColor);
-
- RGBColor fillColor, bkgndColor;
- // Dark blue
- fillColor.red = 0;
- fillColor.green = 13107;
- fillColor.blue = 65535;
- // Light blue
- bkgndColor.red = 39321;
- bkgndColor.green = 52428;
- bkgndColor.blue = 65535;
-
- Rect progressRect = windowBounds;
- InsetRect(&progressRect, 20, 0);
- progressRect.top = windowBounds.top + kProgressBarTop;
- progressRect.bottom = progressRect.top + kProgressBarHeight;
-
- this->progressBar = new ProgressBar(&progressRect,
- maxValue, 0, this->progressWindow, &fillColor, &bkgndColor);
-
- ShowWindow(this->progressWindow);
- this->Update();
- } // END ctor
-
- // ---------------------------------------------------------------------------
-
- ProgressWindow::~ProgressWindow() {
- HideWindow(this->progressWindow);
-
- if (this->progressBar != NULL)
- delete(this->progressBar);
-
- DisposeWindow(this->progressWindow);
- } // END dtor
-
- // ---------------------------------------------------------------------------
-
- void ProgressWindow::Update() {
- EraseRect(&this->progressWindow->portRect);
- this->progressBar->Update();
-
- this->DrawPrimaryString();
- this->DrawSecondaryString();
- } // END Update
-
- // ---------------------------------------------------------------------------
-
- void ProgressWindow::DrawPrimaryString() {
- Rect stringRect;
-
- SetRect(&stringRect, kPrimaryStrLeftPos, kPrimaryStrBotPos - 12,
- this->progressWindow->portRect.right, kPrimaryStrBotPos + 4);
- EraseRect(&stringRect);
- MoveTo(kPrimaryStrLeftPos, kPrimaryStrBotPos);
- if (this->primaryStr[0] > 0)
- DrawString(this->primaryStr);
- } // END DrawPrimaryString
-
- // ---------------------------------------------------------------------------
-
- void ProgressWindow::DrawSecondaryString() {
- Rect stringRect;
-
- SetRect(&stringRect, kSecondaryStrLeftPos, kSecondaryStrBotPos - 12,
- this->progressWindow->portRect.right, kSecondaryStrBotPos + 4);
- EraseRect(&stringRect);
- MoveTo(kSecondaryStrLeftPos, kSecondaryStrBotPos);
- if (this->secondaryStr[0] > 0)
- DrawString(this->secondaryStr);
- } // END DrawSecondaryString
-
- // ---------------------------------------------------------------------------
-
- void ProgressWindow::Increment() {
- this->progressBar->Increment();
- } // END Increment
-
- // ---------------------------------------------------------------------------
-
- void ProgressWindow::IncrementBy(short stepValue) {
- this->progressBar->IncrementBy(stepValue);
- } // END IncrementBy
-
- // ---------------------------------------------------------------------------
-
- void ProgressWindow::IncrementTo(short curValue) {
- this->progressBar->IncrementTo(curValue);
- } // END IncrementTo
-
- // ---------------------------------------------------------------------------
-
- void ProgressWindow::SetPrimaryMessage(Str255 message) {
- if (message != NULL) {
- BlockMove(&message[1], &this->primaryStr[1], message[0]);
- this->primaryStr[0] = message[0];
- }
- else
- this->primaryStr[0] = 0;
-
- this->DrawPrimaryString();
-
- if (this->readDelay > 0) {
- long dummy;
- Delay(readDelay, &dummy);
- }
- } // END SetPrimaryMessage
-
- // ---------------------------------------------------------------------------
-
- void ProgressWindow::SetSecondaryMessage(Str255 message) {
- if (message != NULL) {
- BlockMove(&message[1], &this->secondaryStr[1], message[0]);
- this->secondaryStr[0] = message[0];
- }
- else
- this->secondaryStr[0] = 0;
-
- this->DrawSecondaryString();
-
- if (this->readDelay > 0) {
- long dummy;
- Delay(readDelay, &dummy);
- }
- } // END SetSecondaryMessage
-
- // ---------------------------------------------------------------------------
-
- void ProgressWindow::FinishProgress() {
- while (!this->progressBar->IsDone()) {
- this->progressBar->Increment();
- }
- } // END FinishProgress